//
//  OrderGoodsTableViewCell.m
//  ForestPack
//
//  Created by 郑洲 on 2018/7/20.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "OrderGoodsTableViewCell.h"

@interface OrderGoodsTableViewCell ()

@property (nonatomic, strong) UIImageView *goodsImage;
@property (nonatomic, strong) UILabel *goodsName;
@property (nonatomic, strong) UILabel *goodsMoney;
@property (nonatomic, strong) UILabel *goodsDetail;

@property (nonatomic, strong) UILabel *goodsAll;
@property (nonatomic, strong) UILabel *sendMoney;
@property (nonatomic, strong) UILabel *orderAll;
@property (nonatomic, strong) UILabel *payMoney;

@end

@implementation OrderGoodsTableViewCell

+ (OrderGoodsTableViewCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"OrderGoodsTableViewCell";
    OrderGoodsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[OrderGoodsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

-(void)setShopOrderDetailModel:(ShopOrderDetailModel *)shopOrderDetailModel
{
    _shopOrderDetailModel = shopOrderDetailModel;
    
    [self.goodsImage sd_setImageWithURL:[NSURL URLWithString:self.shopOrderDetailModel.pic]];
    self.goodsName.text = self.shopOrderDetailModel.goods_name;
    self.goodsMoney.text = [NSString stringWithFormat:@"%@元",self.shopOrderDetailModel.total_price];
    
    self.goodsAll.text = [NSString stringWithFormat:@"%@",self.shopOrderDetailModel.total_price];
    self.sendMoney.text = [NSString stringWithFormat:@"%@",self.shopOrderDetailModel.express_fee];
    self.orderAll.text = [NSString stringWithFormat:@"%@",self.shopOrderDetailModel.total_fee];
    self.payMoney.text = [NSString stringWithFormat:@"%@",self.shopOrderDetailModel.pay_price];
}

- (void)createSubView
{
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.5)];
    line.backgroundColor = LineColor;
    [self addSubview:line];
    
    self.goodsImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(140), ScreenX375(78))];
    self.goodsImage.layer.cornerRadius = 5;
    self.goodsImage.clipsToBounds = YES;
    self.goodsImage.image = ImageWithName(@"头部背景");
    [self addSubview:self.goodsImage];
    
    self.goodsName = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(163), ScreenX375(14), ScreenX375(100), ScreenX375(16))];
//    self.goodsName.text = @"纸箱纸板";
    self.goodsName.textColor = FONTCOLOR_BLACK;
    self.goodsName.font = Kfont(14);
    [self addSubview:self.goodsName];
    
    self.goodsMoney = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(110), ScreenX375(14), ScreenX375(100), ScreenX375(16))];
//    self.goodsMoney.text = @"12元";
    self.goodsMoney.textColor = FONTCOLOR_BLACK;
    self.goodsMoney.font = Kfont(14);
    self.goodsMoney.textAlignment = NSTextAlignmentRight;
    [self addSubview:self.goodsMoney];
    
    NSArray *noteArr = @[@"商品总价",@"运费",@"订单总价",@"实付款"];
    for (int i = 0; i < noteArr.count; i++) {
        UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(109) - 0.5 + i * ScreenX375(44), SCREEN_WIDTH - ScreenX375(26), 0.5)];
        line.image = [UIImage imageNamed:@"虚线"];
        [self addSubview:line];
        
        UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(123) + i * ScreenX375(44), ScreenX375(70), ScreenX375(15))];
        noteLabel.text = noteArr[i];
        noteLabel.textColor = FONTCOLOR_BLACK;
        noteLabel.font = Kfont(13);
        [self addSubview:noteLabel];
        
        UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(113), ScreenX375(123) + i * ScreenX375(44), ScreenX375(100), ScreenX375(15))];
//        detailLabel.text = noteArr[i];
        detailLabel.font = Kfont(13);
        detailLabel.textAlignment = NSTextAlignmentRight;
        if (i < 3) {
            detailLabel.textColor = FONTCOLOR_BLACK;
            if (i == 0) {
                _goodsAll = detailLabel;
            }else if (i == 1) {
                _sendMoney = detailLabel;
            }else {
                _orderAll = detailLabel;
            }
        }else {
            detailLabel.textColor = ThemeColor;
            _payMoney = detailLabel;
        }
        [self addSubview:detailLabel];
    }
}


@end
